export default {
  //开启命名空间
  namespaced: true,
  
  //state 数据
  state: () => ({
    //收货地址
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    //登录成功之后的 token 字符串
    // token: uni.getStorageSync('token') || '',
     //token:'',
      token: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo",
    //用户的基本信息
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    
    //重定向的 object 对象 { openType, from}
    redirectInfo: null
  }),
  
  //方法
  mutations: {
    //更新收货地址
    updateAddress(state,address) {
      state.address = address
      this.commit('m_user/saveAddressToStorage')
    },
    
    //1.定义将 address 持久化存储到本地 mutations 方法
    saveAddressToStorage(state) {
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    //更新用户的基本信息
    updateUserInfo(state,userinfo) {
      state.userinfo = userinfo
      this.commit('m_user/saveUserInfoToStorage')
    },
     //将 userinfo 持久化存储到本地
     saveUserInfoToStorage(state) {
       uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))  //键 值
     },
     //更新 token 字符串
     updateToken(state, token) {
       state.token = token
       this.commit('m_user/saveTokenStorage')
     },
     //将 token 字符串持久化存储到本地
     saveTokenStorage(state) {
       uni.setStorageSync('token', state.token)
     },
     //更新重定向的信息对象
     updateRedirectInfo(state, info) {
       state.redirectInfo = info
       //console.log(state.redirectInfo)
     }
  },
  
  
  //数据包装器
  getters: {
    //收货地址的计算属性
    addStr(state) {
      if(!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}